package pro.softzhang.algo.lc100;

import pro.softzhang.algo.common.ListNode;
import pro.softzhang.algo.flag.knowledge.KDoublePointer;
import pro.softzhang.algo.flag.knowledge.KLinkedList;

/**
 * 141. 环形链表
 * https://leetcode.cn/problems/linked-list-cycle
 */
public class LC141_LinkedListCycle {
    public static void main(String[] args) {

    }

    /**
     *
     */
    @KLinkedList
    @KDoublePointer
    static
    class Solution {
        public boolean hasCycle(ListNode head) {
            ListNode slow = head, fast = head;
            while (fast != null && fast.next != null) {
                slow = slow.next;
                fast = fast.next.next;
                if (slow == fast) {
                    return true;
                }
            }
            return false;
        }
    }
}
